package com.xy.controller.mainData;

import com.xy.api.model.dto.mainData.ProductDTO;
import com.xy.api.model.request.mainData.ProductRequest;
import com.xy.api.model.response.R;
import com.xy.api.model.response.Rows;
import com.xy.api.service.mainData.IProductService;
import com.xy.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductController extends BaseController {

    @Autowired
    private IProductService productService;

    @PostMapping("/queryProductList")
    public R queryProductList(@RequestBody ProductRequest request) {
        Rows<ProductDTO> rows = productService.queryProductList(request);
        return success(rows);
    }

    @PostMapping("/queryAllProductList")
    public R queryAllProductList() {
        Rows<ProductDTO> rows = productService.queryAllProductList();
        return success(rows);
    }

    @PostMapping("/queryProductDetail")
    public R<ProductDTO> queryProductDetail(@RequestBody ProductRequest request) {
        ProductDTO product = productService.queryProductDetail(request.getId());
        return success(product);
    }

    @PostMapping("/editProduct")
    public R editProduct(@RequestBody ProductDTO request) {
        productService.editProduct(request);
        return success();
    }

    @PostMapping("/deleteProduct")
    public R deleteProduct(@RequestBody ProductRequest request) {
        productService.deleteProduct(request.getId());
        return success();
    }
}
